Ext.onReady(function() {
	var toolbar = Ext.create('Ext.toolbar.Toolbar', {
		dock : 'top',
		items : [{
			text : '返回',
			xtype : 'button',
			listeners:{
				click: function(){
					location.href="/wuziMgr/bybp";
				}
			}
		},{
			text : '添加',
			xtype : 'button',
			listeners:{
				click: function(){
					var params = {
						GroupId: Ext.getCmp("flight").getValue(),
						DeviceTypeId: Ext.getCmp("device_type").getValue(),
						MinInventory: Ext.getCmp("min_inventory").getValue()
					}
					Ext.Ajax.request({
						url: "/spareparts/add",
						type: "POST",
						params:params,
						callback:function(options, success, response){
							if(success){
								var result = Ext.decode(response.responseText);
								if(result.success){
									location.href = "/wuziMgr/bybp";
								}
								else{
									Ext.Msg.alert("错误", result.msg);
								
								}
							}
						}
					})
				}
			}
		}]
	});
	
	
			
	var flightStore = Ext.create('Ext.data.Store', {
				fields : ["Id", 'Name'],
				proxy : {
					type : 'ajax',
					url : '/flight/all',
					reader : {
						type : 'json',
						root : 'data.rows'
					}
				},
				autoLoad : true
			});

	var flight = Ext.create('Ext.form.ComboBox', {
				fieldLabel : '班组',
				id : 'flight',
				store : flightStore,
				editable : false,
				queryMode : 'local',
				displayField : 'Name',
				valueField : 'Id'
			});
			
	var deviceTypeStore = Ext.create('Ext.data.Store', {
				fields : [{
							name : 'Id',
							type : 'int'
						}, 'Name'],
				proxy : {
					type : 'ajax',
					url : '/device_type/list_no_flight',
					reader : {
						type : 'json',
						root : 'data.rows'
					}
				},
				autoLoad : true
			});

	var deviceType = Ext.create('Ext.form.ComboBox', {
				store : deviceTypeStore,
				id: "device_type",
				queryMode : 'local',
				editable : false,
				fieldLabel: "设备类型",
				displayField : 'Name',
				valueField : 'Id'
			});
			
	var detailPanel = Ext.create("Ext.container.Container",{
		margin: '5 5',
		items: [{
			xtype: 'container',
			layout: 'hbox',
			margin: '5 0',
			items: [deviceType]
		},{
			xtype: 'container',
			layout: 'hbox',
			margin: '5 0',
			items: [flight]
		},{
			xtype: 'container',
			layout: 'hbox',
			margin: '5 0',
			items: [{
				xtype: 'numberfield',
				id: "min_inventory",
				minValue: 0,
        		fieldLabel: '最小库存'
			}]
		}]
	});
	
	var panel = Ext.create("Ext.panel.Panel", {
		title: '',
		border : false,
		bodyBorder : false,
		layout : 'fit',
		dockedItems : [ toolbar ],
		items : [detailPanel]
	});
	Ext.create('Ext.Viewport', {
		layout : 'fit',
		style : 'background:none;background-color:white;',
		items : [ panel ]
	});
});